package com.yadong.smarthome2.device;

import java.util.List;

import com.yadong.smarthome2.protocol2.ResultProtocol.DeviceInfo.DeviceType;
import com.yadong.smarthome2.protocol2.ResultProtocol.DeviceInfo.Status;
import com.yadong.smarthome2.protocol2.ResultProtocol.Function;

public class Device {
    public enum DeviceConnectionType {
        UNKNOWN, WIFI, WIFIP2P, BLUETOOTH, BLE
    }

    public enum DeviceState {
        NEW, PAIRED, CONNECTED, FUNCIONLOADED
    }

    public static final int DEVICE_TYPE_ELECTRIC = 1;
    public static final int DEVICE_TYPE_SENSOR = 2;

    private long mId = -1;
    private DeviceConnectionType mDeviceConnectionType;
    private DeviceType mDeviceType;

    private String mDeviceDescription;
    //for wifi device, address is ip, for bt device , address is mac
    private String mAddress;
    private List<Function> mFunctions;
    private List<Status> mStatus;
    private int mDeviceInfoVersion;
    private DeviceState mState = DeviceState.NEW;
    private String mMac;

    public Device(DeviceConnectionType type, String mAddress,
            String description, String mac) {
        this.mDeviceConnectionType = type;
        this.mAddress = mAddress;
        this.mDeviceDescription = description;
        this.mMac = mac;
    }

    public DeviceType getDeviceType() {
        return mDeviceType;
    }

    public int getDeviceInfoVersion() {
        return mDeviceInfoVersion;
    }


    public void setDeviceInfoVersion(int deviceInfoVersion) {
        this.mDeviceInfoVersion = deviceInfoVersion;
    }


    public long getId() {
        return mId;
    }

    public void setId(long id) {
        this.mId = id;
    }

    public void setDeviceDescription(String deviceDescription) {
        this.mDeviceDescription = deviceDescription;
    }


    public void setAddress(String address) {
        this.mAddress = address;
    }


    public String getMac() {
        return mMac;
    }

    public void setState(DeviceState state) {
        this.mState = state;
    }

    public List<Status> getStatus() {
        return mStatus;
    }

    public void setStatus(List<Status> status) {
        this.mStatus = status;
    }

    public DeviceState getState() {
        return mState;
    }

    public DeviceConnectionType getDeviceConnectionType() {
        return mDeviceConnectionType;
    }

    public String getDeviceDescription() {
        return mDeviceDescription;
    }

    public String getAddress() {
        return mAddress;
    }

    public List<Function> getFunctions() {
        return mFunctions;
    }

    public void init(DeviceType deviceType, int deviceInfoVersion,
            List<Function> functions, List<Status> status) {
        this.mDeviceType = deviceType;
        this.mDeviceInfoVersion = deviceInfoVersion;
        this.mFunctions = functions;
        this.mStatus = status;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Device)) {
            return false;
        }
        if (mMac == null && ((Device)o).mMac != null) {
            return false;
        }
        return mMac.equals(((Device)o).mMac);
    }

    @Override
    public String toString() {
        return "Device [mId=" + mId + ", mDeviceConnectionType=" + mDeviceConnectionType
                + ", mDeviceType=" + mDeviceType + ", mDeviceDescription=" + mDeviceDescription
                + ", mAddress=" + mAddress + ", mFunctions=" + mFunctions + ", mStatus=" + mStatus
                + ", mDeviceInfoVersion=" + mDeviceInfoVersion + ", mState=" + mState + ", mMac="
                + mMac + "]";
    }
}
